package com.itheima.controller;

import com.itheima.common.Code;
import com.itheima.common.Result;
import com.itheima.pojo.OrderForm;
import com.itheima.service.OrderFormService;
import com.itheima.vo.PagingQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @author :WuJunJie
 * packageName :com.itheima.controller
 * fileName :OrderFormController
 * creationTime :2022-11-25 16:14
 */
@RestController
@RequestMapping("order")
public class OrderFormController {
    @Autowired
    private OrderFormService orderFormService;

    @PutMapping
    public Result changeStatus(@RequestBody OrderForm orderForm){
        Boolean change=orderFormService.changeStatus(orderForm);
        if (change){
            return Result.success();
        }
        return Result.error(Code.Forbidden.getCode());
    }

    @GetMapping("page")
    public Result selectPage(
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
            @RequestParam(name = "beginTime",required = false)LocalDateTime beginTime,
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
            @RequestParam(name="endTime",required = false)LocalDateTime endTime,
                             @RequestParam(name="number",required = false)String number,
                             @RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
                             @RequestParam(name = "pageSize",required = false,defaultValue = "2") Integer pageSize){
            PagingQueryVo<OrderForm> pagingQueryVo=orderFormService.selectPage(beginTime,endTime,number,page,pageSize);

        return Result.success(pagingQueryVo);
    }
}
